<template>
  <div class="customer">
    <el-row style="margin-top: 15px;padding: 20px 0;">
      <el-col :span="24">
        <el-button type="primary" @click="goBack()">返回
        </el-button>
      </el-col>
    </el-row>
    <el-form :model="form" style="background-color: #FFFFFF;padding: 20px 0;">
      <el-form-item label="banner图名称：" label-width="150px">
        <el-input auto-complete="off" v-model="form.bannerName" style="width: 50%;" :maxlength="50"></el-input>
      </el-form-item>
      <!--  <el-form-item label="排序值：" label-width="150px">
                <el-input auto-complete="off" v-model="form.orderValue" style="width: 50%;"></el-input>
            </el-form-item> -->
      <el-form-item label="图片：" label-width="150px">
        <we-ui-uploads :images="form.bannerIcon" :maxCount="1" :maxSize="1024*512" @uploading="uploading"></we-ui-uploads>
      </el-form-item>
      <!--             <el-form-item label="是否跳转：" label-width="150px">
                <el-radio-group v-model="form.hashref">
                    <el-radio label="1">是</el-radio>
                    <el-radio label="0">否</el-radio>
                </el-radio-group>
            </el-form-item> -->
      <el-form-item label="跳转类型：" label-width="150px">
        <el-select v-model="form.bannerType" style="width: 120px;" @change="changeType()">
          <el-option label="单商品" value="D"></el-option>
          <el-option label="多商品" value="DD"></el-option>
          <el-option label="链接" value="L"></el-option>
          <el-option label="商家" value="DP"></el-option>
          <el-option label="文章" value="T"></el-option>
          <el-option label="不跳转" value="B"></el-option>
		  <el-option label="商家入驻" value="S"></el-option>
        </el-select>
        &nbsp;温馨提示：更换跳转类型后，会清空之前跳转类型数据，请慎重操作
      </el-form-item>
      <el-form-item label="选择文章：" label-width="150px" style="display: inline-block" v-if="form.bannerType=='T'">
        <el-button size="small" type="primary" @click="fetchArticle(1);dialogTableVisible=true">选择文章
        </el-button>
        {{article}}
      </el-form-item>
      <el-form-item label="选择单商品：" label-width="150px" style="display: inline-block" v-if="form.bannerType=='D'">
        <el-button size="small" type="primary" @click="clean();fetchGoods(1);dialogTableVisible2=true">选择单商品
        </el-button>
      </el-form-item>
      <el-form-item label="选择多商品：" label-width="150px" style="display: inline-block" v-if="form.bannerType=='DD'">
        <el-button size="small" type="primary" @click="clean();fetchGoods(1);dialogTableVisible3=true">选择多商品
        </el-button>
      </el-form-item>
      <el-form-item label="选择商家：" label-width="150px" style="display: inline-block" v-if="form.bannerType=='DP'">
        <el-button size="small" type="primary" @click="fetchBrand(1);dialogTableVisible4=true">选择商家
        </el-button>
      </el-form-item>
      <el-form-item label="链接：" label-width="150px" v-if="form.bannerType=='L'">
        <el-input auto-complete="off" v-model="form.bannerContent" style="width: 50%;"></el-input>
      </el-form-item>
      <el-table :data="pageInfo2.dtos" style="margin-bottom: 20px;" v-if="form.bannerType=='D' || form.bannerType=='DD'" key="table1">
        <el-table-column label="排序值" width="110">
          <template scope="scope">
            <!-- <el-input  v-model="scope.row.sort_value" style="width: 80px;" @blur="editOrder(scope.row,$event)" @focus="setOldProbability(scope.row,scope.row.sort_value)"></el-input> -->
            <el-button @click="setOldProbability(scope.row,scope.row.sort_value);showDilog(scope.row)">{{ scope.row.sort_value }}</el-button>
          </template>
        </el-table-column>
        <el-table-column width="300" label="商品名称">
          <template scope="scope">
            <div style="display: inline-block;">
              <img class="banner" :src="scope.row.goodCover" style="width:120px;" >
                    </div>
              <div style="display: inline-block;width: 120px;vertical-align: middle;padding: 10px;">{{scope.row.goodName}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="DIS_PRICE" label="分类">
          <template scope="scope">
            <span>{{ scope.row.goodOneCateName }} - {{ scope.row.goodTwoCateName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="good_Price" label="起售价（元）">
          <template scope="scope">
            <span>{{ scope.row.goodPrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="T1.good_Discount_Price" label="优惠价（元）">
          <template scope="scope">
            <span v-if="scope.row.goodIsDiscount==1">{{ scope.row.goodDiscountPrice }}</span>
            <span v-else>未启用</span>
          </template>
        </el-table-column>
        <el-table-column prop="good_Ratio" label="补贴比例">
          <template scope="scope">
            <span>{{ scope.row.goodRatio*100 }}%</span>
          </template>
        </el-table-column>
        <el-table-column prop="sales" label="销量">
        </el-table-column>
        <el-table-column prop="stock" label="库存">
        </el-table-column>
        <el-table-column prop="cre_Time" label="上架时间">
          <template scope="scope">
            <span>{{scope.row.creTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template scope="scope">
            <el-button @click.native.prevent="deleteRow(scope.$index,scope.row.goodId)" type="danger" size="small">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-table :data="storeInfoDtos"  v-if="form.bannerType=='DP'" style="margin-bottom: 20px;" key="table2">
        <el-table-column  prop="storeId" label="编号" width="150">
        </el-table-column>
        <el-table-column prop="storeName" label="商家名称">
        </el-table-column>
        <el-table-column prop="userId" label="用户ID">
        </el-table-column>
        <el-table-column prop="contactNum" label="注册手机号">
        </el-table-column>
        <el-table-column prop="contactNum" label="商家类型">
          <template scope="scope">
            <span>{{ findState(scope.row.storeType,merchantType) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="DIS_PRICE" label="分类">
          <template scope="scope">
            <span>{{ scope.row.classifyName }} - {{ scope.row.subClassifyName }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="paginate" v-if="form.bannerType=='D' || form.bannerType=='DD'">
        <el-pagination @current-change="handleCurrentChange2" :current-page="pageInfo2.pageNum" :page-size="pageInfo2.pageSize" layout="total, prev, pager, next, jumper" :total="pageInfo2.count">
        </el-pagination>
      </div>
      <div style="margin-left: 70px;">
        <el-button type="primary" @click="submit()" :disabled="!form.bannerName" :loading="loading">保 存
        </el-button>
      </div>
    </el-form>
    <!--选择文章-->
    <el-dialog title="选择文章" v-model="dialogTableVisible">
      标题：<el-input v-model="topic" style="width:120px;margin-bottom: 20px;"></el-input>
      <el-button type="primary" @click="fetchArticle(1)">查询</el-button>
      <el-table :data="pageInfo.dtos">
        <el-table-column label="编号" width="150">
          <template scope="scope">
            <el-radio class="radio" :label="scope.row" v-model="checked">{{scope.row.noticeCode}}</el-radio>
          </template>
        </el-table-column>
        <el-table-column property="noticeTitle" label="标题"></el-table-column>
      </el-table>
      <div class="paginate" style="float: left;">
        <el-pagination @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize" layout="total, prev, pager, next, jumper" :total="pageInfo.count">
        </el-pagination>
      </div>
      <div style="float: right;margin-top:19px;margin-right: 20px;">
        <el-button type="primary" @click="onSubmit()">确定</el-button>
      </div>
    </el-dialog>
    <!--选择单个商品-->
    <el-dialog title="选择单个商品" v-model="dialogTableVisible2" size="large">
      <el-row>
        <el-col :span="24">
          <el-form :inline="true" class="demo-form-inline" label-width="80px">
            <el-form-item label="商品名称">
              <el-col :span="18">
                <el-input v-model="formInline.goodName"></el-input>
              </el-col>
            </el-form-item>
            <el-button type="primary" @click="fetchGoods(1)">查询</el-button>
          </el-form>
        </el-col>
      </el-row>
      <el-table :data="pageInfo.dtos">
        <el-table-column label="编号" width="180">
          <template scope="scope">
            <el-radio class="radio" :label="scope.row" v-model="checked">{{scope.row.goodId}}</el-radio>
          </template>
        </el-table-column>
        <el-table-column width="215" label="商品">
          <template scope="scope">
            <div style="display: inline-block;">
              <img class="banner" :src="scope.row.goodCover" style="width:55px;">
                        </div>
              <div style="display: inline-block;width: 120px;vertical-align: middle;padding: 10px;">{{scope.row.goodName}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="DIS_PRICE" label="分类">
          <template scope="scope">
            <span>{{ scope.row.goodOneCateName }} - {{ scope.row.goodTwoCateName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="good_Price" sortable='custom' label="起售价（元）">
          <template scope="scope">
            <span>{{ scope.row.goodPrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="T1.good_Discount_Price" label="优惠价（元）">
          <template scope="scope">
            <span v-if="scope.row.goodIsDiscount==1">{{ scope.row.goodDiscountPrice }}</span>
            <span v-else>未启用</span>
          </template>
        </el-table-column>
        <el-table-column prop="good_Ratio" label="补贴比例">
          <template scope="scope">
            <span>{{ scope.row.goodRatio*100 }}%</span>
          </template>
        </el-table-column>
        <el-table-column prop="sales" label="销量">
        </el-table-column>
        <el-table-column prop="stock" label="库存">
        </el-table-column>
        <el-table-column prop="cre_Time" label="上架时间">
          <template scope="scope">
            <span>{{scope.row.creTime}}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="paginate" style="float: left;">
        <el-pagination @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize" layout="total, prev, pager, next, jumper" :total="pageInfo.count">
        </el-pagination>
      </div>
      <div style="float: right;margin-top:19px;margin-right: 20px;">
        <el-button type="primary" @click="onSubmit()">确定</el-button>
      </div>
    </el-dialog>
    <!--选择多个商品-->
    <el-dialog title="选择商品" v-model="dialogTableVisible3" size="large">
      <el-row>
        <el-col :span="24">
          <el-form :inline="true" class="demo-form-inline" label-width="80px">
            <el-form-item label="商品名称">
              <el-col :span="18">
                <el-input v-model="formInline.goodName"></el-input>
              </el-col>
            </el-form-item>
            <!--  <el-form-item label="按分类：">
                        <el-select v-model="formInline.classifyCode" style="width: 120px;" @change="selectSort()">
                            <el-option label="全部" value=""></el-option>
                            <el-option :label="item.classifyName" :value="item.classifyName" v-for="item in sortList"></el-option>
                        </el-select>
                        <el-select v-model="formInline.secondCode" style="width: 120px;" v-if="formInline.classifyCode"  @change="selectSort2()">
                            <el-option label="全部" value=""></el-option>
                            <el-option :label="item.classifyName" :value="item.classifyName" v-for="item in secondList"></el-option>
                        </el-select>
                        <el-select v-model="formInline.thcondCode" style="width: 120px;" placeholder="二级分类" v-if="formInline.secondCode">
                            <el-option label="全部" value=""></el-option>
                            <el-option :label="item.classifyName" :value="item.classifyName"
                                   v-for="item in thirdList"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="按状态：">
                        <el-select v-model="formInline.normalState" style="width: 120px;" >
                            <el-option label="全部" value=""></el-option>
                            <el-option label="已启用" value="1" ></el-option>
                            <el-option label="已禁用" value="2" ></el-option>
                        </el-select>
                    </el-form-item> -->
            <el-button type="primary" @click="fetchGoods(1)">查询</el-button>
          </el-form>
        </el-col>
      </el-row>
      <el-table :data="pageInfo.dtos">
        <el-table-column width="215" label="商品">
          <template scope="scope">
            <div style="display: inline-block;">
              <img class="banner" :src="scope.row.goodCover" style="width:55px;">
                    </div>
              <div style="display: inline-block;width: 120px;vertical-align: middle;padding: 10px;">{{scope.row.goodName}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="DIS_PRICE" label="分类">
          <template scope="scope">
            <span>{{ scope.row.goodOneCateName }} - {{ scope.row.goodTwoCateName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="good_Price" sortable='custom' label="起售价（元）">
          <template scope="scope">
            <span>{{ scope.row.goodPrice }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="T1.good_Discount_Price" label="优惠价（元）">
          <template scope="scope">
            <span v-if="scope.row.goodIsDiscount==1">{{ scope.row.goodDiscountPrice }}</span>
            <span v-else>未启用</span>
          </template>
        </el-table-column>
        <el-table-column prop="good_Ratio" label="补贴比例">
          <template scope="scope">
            <span>{{ scope.row.goodRatio*100 }}%</span>
          </template>
        </el-table-column>
        <el-table-column prop="sales" label="销量">
        </el-table-column>
        <el-table-column prop="stock" label="库存">
        </el-table-column>
        <el-table-column prop="cre_Time" label="上架时间">
          <template scope="scope">
            <span>{{scope.row.creTime}}</span>
          </template>
        </el-table-column>
        <el-table-column label="选择" width="150">
          <template scope="scope">
            <el-checkbox-group v-model="checked" :max="100" @change="handleCheckedCitiesChange">
              <el-checkbox :label="scope.row">选择</el-checkbox>
            </el-checkbox-group>
          </template>
        </el-table-column>
      </el-table>
      <div class="paginate" style="float: left;">
        <el-pagination @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize" layout="total, prev, pager, next, jumper" :total="pageInfo.count">
        </el-pagination>
      </div>
      <div style="float: right;margin-top:19px;margin-right: 20px;">
        <el-checkbox v-model="checkAll" @change="handleCheckAllChange" style="margin-right: 40px;" :indeterminate="isIndeterminate">全选</el-checkbox>
        <el-button type="primary" @click="onSubmit()">确定</el-button>
      </div>
    </el-dialog>
    <!--选择商家-->
    <el-dialog title="选择商家" v-model="dialogTableVisible4">
      <!-- 标题：<el-input v-model="storeName" style="width:120px;margin-bottom: 20px;"></el-input>
            <el-button type="primary" @click="fetchBrand(1)">查询</el-button> -->
      <el-table :data="pageInfo.dtos">
        <el-table-column label="编号" width="150">
          <template scope="scope">
            <el-radio class="radio" :label="scope.row" v-model="checked">{{scope.row.storeId}}</el-radio>
          </template>
        </el-table-column>
        <el-table-column prop="storeName" label="商家名称">
        </el-table-column>
        <el-table-column prop="userId" label="用户ID">
        </el-table-column>
        <el-table-column prop="contactNum" label="注册手机号">
        </el-table-column>
        <el-table-column prop="contactNum" label="商家类型">
          <template scope="scope">
            <span>{{ findState(scope.row.storeType,merchantType) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="DIS_PRICE" label="分类">
          <template scope="scope">
            <span>{{ scope.row.classifyName }} - {{ scope.row.subClassifyName }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="paginate" style="float: left;">
        <el-pagination @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-size="pageInfo.pageSize" layout="total, prev, pager, next, jumper" :total="pageInfo.count">
        </el-pagination>
      </div>
      <div style="float: right;margin-top:19px;margin-right: 20px;">
        <el-button type="primary" @click="onSubmit()">确定</el-button>
      </div>
    </el-dialog>
    <!--排序值-->
    <el-dialog title="排序值" v-model="dialogTableVisible5" size="tiny">
      <div style="text-align: center;">
        <el-input v-model="f.sort_value" style="width:150px;"></el-input>
        <div style="margin-top:19px;margin-right: 20px;margin-bottom: 20px;">
          <el-button type="primary" @click="editOrder(f,f.sort_value)">确定</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<style>
</style>
<script>
export default {
  data() {
    return {
      pageInfo: {
        pageNum: 1,
        pageSize: 1,
        count: 1,
        dtos: []
      },
      pageInfo2: {
        pageNum: 1,
        pageSize: 1,
        count: 1,
        dtos: []
      },
      dialogVisible: false,
      table_loading: false,
      tableData: [],
      form: {
        hashref: 1,
        bannerIcon: [],
        bannerName: '',
        orderValue: 0,
        loaction: 0,
        bannerCode: null,
        articleId: 0,
        goodId: 0,
        bannerType: '',
        bannerContent: '',
        thcondCode: ''
      },
      dialogTableVisible: false,
      dialogTableVisible2: false,
      dialogTableVisible3: false,
      dialogTableVisible4: false,
      dialogTableVisible5: false,
      checked: [],
      article: '',
      goodName: '',
      goods: '',
      alternative: '2',
      URL: URL,
      loading: false,
      loading2: false,
      formInline: {
        goodName: '',
        goodOneCate: '',
        goodTwoCate: '',
        goodState: 2,
        storeId: '',
        pageNum: 1,
        pageSize: 5,
        sort: 'T1.CRE_TIME',
        desc: 'DESC',
        goodIsDiscount: ''
      },
      gridData: [],
      checkAll: false,
      isIndeterminate: true,
      arr: [],
      storeGoodDtos: [],
      new_storeGoodDtos: [],
      sortList: [],
      secondList: [],
      storeName: '',
      thirdList: [],
      flag2: false,
      topic: '',
      status: false,
      old: '',
      show: true,
      f: {},
      storeInfoDtos:[]
    }
  },
  created() {
    this.form = {
      hashref: 1,
      bannerIcon: [],
      bannerName: '',
      orderValue: 0,
      loaction: 0,
      bannerCode: null,
      articleId: 0,
      goodId: 0,
      bannerType: '',
      bannerContent: ''
    }
    // this.fetchList()
    this.fetchData()
  },
  watch: {
    'form.bannerType'(val, oldVal) {
      this.old = oldVal

    }
  },
  methods: {
    fetchData() {
      let rid = this.$route.params.id
      if (rid === 'addCk') return;
      this.dataApi.ajax('bannerSingle', { bannerCode: rid }, res => {
        if (res.responseType === 'S') {
          this.form = res
          this.form.bannerIcon = [res.bannerIcon]
          if (res.bannerType == 'D') {
            this.pageInfo2 = {
              pageNum: 1,
              pageSize: 1,
              count: 1,
              dtos: res.storeGoodDtos
            }
          } else if (res.bannerType == 'DD') {
            this.pageInfo2 = {
              pageNum: 1,
              pageSize: 5,
              count: 1,
              dtos: []
            }
            for (var i = res.storeGoodDtos.length - 1; i >= 0; i--) {
              res.storeGoodDtos[i].sort_value = i + 1
              res.storeGoodDtos[i].index = i
              res.storeGoodDtos[i].OldProbability = i + 1
            }
            let arr = generateArr(res.storeGoodDtos)
            this.storeGoodDtos = res.storeGoodDtos
            this.pageInfo2.count = res.storeGoodDtos.length
            this.pageInfo2.dtos = arr.splice(0, 5)
          } else if (res.bannerType == 'DP') {
            this.storeName = res.storeInfoDtos[0].storeName;
            this.storeInfoDtos=res.storeInfoDtos;
          } else if (res.bannerType == 'T') {
            this.article = res.noticTitle
          }

          this.old = res.bannerType
        }
      });
    },
    fetchArticle(page = 1) {
      this.table_loading = true;
      this.pageInfo.pageNum = page
      this.dataApi.ajax('selectPageSysNotice', {
        pageNum: this.pageInfo.pageNum,
        pageSize: 5,
        sort: 'CRE_TIME',
        desc: 'DESC',
        topic: this.topic
      }, res => {
        //console.log(res)
        this.table_loading = false;
        if (res.responseType === 'S') {
          this.pageInfo = res
        }
      });
    },
    fetchGoods(page = 1) {
      this.checked = []
      this.table_loading = true;
      this.pageInfo.pageNum = page;
      this.formInline.pageNum = page
      this.dataApi.ajax('selectPageStoreGood', this.formInline, res => {
        this.table_loading = false;
        if (res.responseType === 'S') {
          this.pageInfo = res
          if (this.form.bannerType == 'DD') {
            this.gridData = res.dtos
            this.arr = []
            for (var i = this.gridData.length - 1; i >= 0; i--) {
              this.arr.push(this.gridData[i])
            }
            if (this.checked.length == this.arr.length) {
              this.checkAll = true
            } else {
              this.checkAll = false;
            }
          }
        }
      });

    },
    fetchList() {
      this.dataApi.ajax('MallGoodClassifyControl/selectOneList', null, res => {
        if (res.responseType === 0) {
          this.sortList = res.goodsClassifyPojos
        }
      });
    },
    fetchBrand(page = 1) {
      this.table_loading = true;
      this.pageInfo.pageNum = page
      this.dataApi.ajax('selectPageStoreInfo', {
        pageNum: this.pageInfo.pageNum,
        pageSize: 5,
        sort: 'CRT_TIME',
        desc: 'DESC',
        storeStat:1,
        actStat:4
      }, res => {
        this.table_loading = false;
        if (res.responseType === 'S') {
          this.pageInfo = res
        }
      });
    },
    selectSort() {
      this.formInline.secondCode = ''
      this.formInline.thcondCode = ''
      this.dataApi.ajax('MallGoodClassifyControl/selectListOne', { classifyName: this.formInline.classifyCode }, res => {
        if (res.responseType === 0) {
          this.secondList = res.goodsClassifyPojos
        }
      });
    },
    selectSort2() {
      if (this.flag2 === true) this.formInline.thcondCode = ''
      this.flag2 = true;
      this.dataApi.ajax('MallGoodClassifyControl/selectListOne', { classifyName: this.formInline.secondCode }, res => {
        //console.log(res)
        if (res.responseType === 0) {
          this.thirdList = res.goodsClassifyPojos
        }
      });
    },
    onSubmit() {

      if (this.form.bannerType == 'D') {
        this.dialogTableVisible2 = false
        this.pageInfo2.dtos = []
        this.pageInfo2.dtos.push(this.checked)
      } else if (this.form.bannerType == 'DD') {

        this.dialogTableVisible3 = false
        // this.pageInfo2.dtos=this.checked
        for (var key in this.storeGoodDtos) {
          for (var i in this.checked) {
            if (this.storeGoodDtos[key].goodId.indexOf(this.checked[i].goodId) !== -1) {
              this.checked.splice([i], 1)
            }
          }
        }

        if (this.checked.length <= 0) {
          return false;
        }
        this.storeGoodDtos = this.storeGoodDtos.concat(this.checked)
        for (var i = this.storeGoodDtos.length - 1; i >= 0; i--) {
          this.storeGoodDtos[i].sort_value = i + 1
          this.storeGoodDtos[i].index = i
          this.storeGoodDtos[i].OldProbability = i + 1
        }
        var arr = generateArr(this.storeGoodDtos)
        this.pageInfo2.count = this.storeGoodDtos.length
        this.pageInfo2.dtos = arr.splice(0, 5)
      } else if (this.form.bannerType == 'DP') {
        this.dialogTableVisible4 = false
        this.storeName = this.checked.storeName
        this.form.bannerContent = this.checked.storeId
        this.storeInfoDtos=[this.checked]
      } else if (this.form.bannerType == 'T') {
        this.dialogTableVisible = false
        this.article = this.checked.noticeTitle
        this.form.bannerContent = this.checked.noticeCode
      }

    },
    submit() {
      if (this.form.bannerIcon == '') {
        this.showMsg('请上传图片', 'warning');
        return
      }
      let obj = generateObj(this.form);
      obj.bannerIcon = obj.bannerIcon + '';
      if (obj.bannerType == 'D') {
        if (this.pageInfo2.dtos.length == 0) {
          this.showMsg('请选择商品', 'warning');
          return;
        }
        obj.bannerContent = this.checked.goodId
      } else if (obj.bannerType == 'DD') {
        if (this.storeGoodDtos.length == 0) {
          this.showMsg('请选择商品', 'warning');
          return;
        }
        var arr = []
        for (var i = 0; i < this.storeGoodDtos.length; i++) {
          arr[i] = this.storeGoodDtos[i].goodId
        }
        obj.bannerContent = arr.join(',')
      } else if (obj.bannerType == 'L') {
        if (!obj.bannerContent) {
          this.showMsg('请填写链接', 'warning');
          return;
        }
        obj.bannerContent = this.form.bannerContent
      } else if (obj.bannerType == 'DP') {
        if (!this.storeName) {
          this.showMsg('请选择商家', 'warning');
          return;
        }
        if (this.checked.length != 0) {
          obj.bannerContent = this.checked.storeId
        }

      } else if (obj.bannerType == 'T') {
        if (!this.article) {
          this.$message({
            type: 'warning',
            message: '请选择文章!'
          });
          return;

        }
        if (this.checked.length != 0) {
          obj.bannerContent = this.checked.noticeCode
        }
      }else if(obj.bannerType == 'B'){
         obj.bannerContent='';
      }
      this.loading = true
      console.log(obj)
   
      if (!obj.bannerCode) {
		  if(this.$route.params.id=='addCk'){
			  obj.bannerPosition='CK'			
		  }  
        this.dataApi.ajax('bannerAdd', obj, res => {
          //console.log(res)
          if (res.responseType === 'S') {
            this.showMsg('添加成功');
            this.loading = false;
            goBack();
          }
        });
      } else {
        this.dataApi.ajax('bannerEdit', obj, res => {
          if (res.responseType === 'S') {
			  if(this.$route.params.id=='addCk'){
			  			  obj.bannerPosition='CK'			
			  }  
            this.loading = false;
            this.showMsg('修改成功');
            goBack();
          }
        });
      }


    },
    handleCurrentChange(val) {
      if (this.form.bannerType == 'D') {
        this.fetchGoods(val)
      } else if (this.form.bannerType == 'DD') {
        this.fetchGoods(val)
      } else if (this.form.bannerType == 'DP') {
        this.fetchBrand(val)
      } else if (this.form.bannerType == 'T') {
        this.fetchArticle(val)
      }
    },
    handleCurrentChange2(val) {
      this.pageInfo2.pageNum = val
      // console.log(arr.splice(5*(val-1),(5*(val-1)+5)))
      var arr2 = []
      var arr = generateArr(this.storeGoodDtos)
      arr2 = arr.slice(5 * (val - 1), (5 * (val - 1) + 5))
      this.pageInfo2.dtos = arr2
    },
    uploading(f) {
      this.loading=true;
      this.dataApi.upload('FileUploadNotify/upload', f.file, res => {
            //console.log(res)
            if (res.responseType == 'S') {
                f.images.splice(f.index,1,res.filePath);
                this.loading=false;
            }
        });

    },
    handleCheckAllChange(event) {

      if (event.target.checked == false) {
        for (var i = this.arr.length - 1; i >= 0; i--) {
          for (var j = this.checked.length - 1; j >= 0; j--) {
            if (this.arr.indexOf(this.checked[j]) !== -1) {
              this.checked.splice(j, 1)
            }
          }
        }

      } else {
        this.isIndeterminate = false;
        for (var i = this.gridData.length - 1; i >= 0; i--) {
          if (this.checked.indexOf(this.arr[i]) === -1) {
            this.checked.push(this.arr[i])
          }
        }
      }


    },
    handleCheckedCitiesChange(value) {

      let arr = []
      for (var i = this.arr.length - 1; i >= 0; i--) {
        for (var j = this.checked.length - 1; j >= 0; j--) {
          if (arr.indexOf(this.checked[j]) === -1 && this.arr[i] === this.checked[j]) {
            arr.push(this.checked[j])
          }
        }
      }


      let checkedCount = arr.length;
      this.checkAll = checkedCount === this.arr.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.arr.length;
    },
    deleteRow(index, id) {
      this.pageInfo2.dtos.splice(index, 1);
      // this.storeGoodDtos.splice(index, 1);
      for (var i = this.storeGoodDtos.length - 1; i >= 0; i--) {
        if (this.storeGoodDtos[i].goodId.indexOf(id) !== -1) {
          this.storeGoodDtos.splice([i], 1)
        }
      }
      for (var i = this.storeGoodDtos.length - 1; i >= 0; i--) {
        this.storeGoodDtos[i].sort_value = i + 1
        this.storeGoodDtos[i].index = i
        this.storeGoodDtos[i].OldProbability = i + 1
      }
      this.handleCurrentChange2(this.pageInfo2.pageNum)
      this.pageInfo2.count = this.storeGoodDtos.length
    },
    editOrder(item, e) {
      // console.log(item.index)

      // var arr_old=generateArr(this.storeGoodDtos)
      // this.storeGoodDtos=[]
      // this.storeGoodDtos=arr_old 
      // this.pageInfo2.dtos=[]
      var val = e //输入的排序值
      if (!isFloat(e)) {
        this.showMsg('输入的排序值不正确', 'warning')
        return
      }
      // console.log(e.target.value,item.OldProbability)
      // return;
      if (Math.floor(val) <= 0) {
        val = item.OldProbability || 0;
        return false;
      }
      if (item.OldProbability == val) return false;
      if (val > this.storeGoodDtos.length) {
        this.showMsg('排序值不能大于总数', 'warning')
        item.sort_value = item.OldProbability
        return false;
      }
      //let currentList = this.pageInfo2.dtos;

      let newVal = this.storeGoodDtos[item.index] //获取当前的元素值


      let oldVal = this.storeGoodDtos[val - 1] //获取要替换的元素值



      this.storeGoodDtos.splice(val - 1, 1, newVal) //替换旧值并新增的新值
      this.storeGoodDtos.splice(item.index, 1, oldVal) //替换新值并新增的旧值
      // console.log(this.storeGoodDtos,item.OldProbability-1,index-1)
      // console.log(item.OldProbability,val)//旧的排序值

      oldVal.index = item.index
      newVal.index = parseInt(val - 1)

      // oldVal.sort_value = oldVal.index+1+""
      // newVal.sort_value = newVal.index+1+""

      for (var i = this.storeGoodDtos.length - 1; i >= 0; i--) {

        // this.$set(this.storeGoodDtos[i],'sort_value',this.storeGoodDtos[i].index+1+"")
        this.storeGoodDtos[i].sort_value = this.storeGoodDtos[i].index + 1 + ""

        //console.log(this.storeGoodDtos[i].sort_value);
      }

      this.handleCurrentChange2(this.pageInfo2.pageNum) //根据所有数据数组切割成当前页数组
      this.dialogTableVisible5 = false
    },
    setOldProbability(item, index) {
      item.OldProbability = index
    },
    clean() {
      this.formInline = {
        goodName: '',
        goodOneCate: '',
        goodTwoCate: '',
        goodState: 2,
        storeId: '',
        pageNum: 1,
        pageSize: 5,
        sort: 'T1.CRE_TIME',
        desc: 'DESC',
        goodIsDiscount: ''
      }
    },
    changeType() {

      if (!this.status) {
        this.status = true
        return;
      }
      this.pageInfo2 = {
        pageNum: 1,
        pageSize: 5,
        count: 1,
        dtos: []
      }
      this.article = ''
      this.storeName = ''
      this.form.bannerContent = ''
      this.checked = []
      this.storeGoodDtos = []
      this.storeInfoDtos=[]
    },
    showDilog(item) {
      this.dialogTableVisible5 = true
      this.f = item
    }
  }
}

</script>
